package ssm_zxw.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import ssm_zxw.mapper.RoleMapper;
import ssm_zxw.pojo.Role;
import ssm_zxw.service.roleService;

import javax.swing.plaf.PanelUI;
import java.util.List;

@Controller
@RequestMapping("/role")
public class roleController {
    @Autowired
    private roleService service;

    @RequestMapping("/findAll")
    @ResponseBody
    public ModelAndView findAll(){
        List<Role> list = service.findAll();
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.addObject("roleList",list);
        modelAndView.setViewName("role-list");
        return modelAndView;
    }

    @RequestMapping("/addRole")
    public String addRole(Role role){
        service.addRole(role);
        return "redirect:/role/findAll";
    }
    @RequestMapping("/deleteRole/{id}")
    public String deleteRole(@PathVariable(value = "id") int id){
        service.deleteRole(id);
        return "redirect:/role/findAll";
    }

}
